/**
 * 
 */
package cc.comac.mom.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cc.comac.mom.api.EquipCheckDetailService;
import cc.comac.mom.api.EquipCheckService;
import cc.comac.mom.bean.EquipCheck;
import cc.comac.mom.bean.EquipCheckBean;
import cc.comac.mom.bean.EquipCheckDetail;
import cc.comac.mom.bean.EquipCheckDetailBean;
import cc.comac.mom.util.ResultBean;
import io.swagger.annotations.ApiOperation;

/**
 * @Description:
 * @author: fyt
 * @date: 2020年7月21日下午3:14:30
 */
@RestController
@RequestMapping("/EquipCheck")
public class EquipCheckController {
	@Autowired
	private EquipCheckService equipCheckService;

	@Autowired
	private EquipCheckDetailService equipCheckDetailService;

	@ApiOperation(value = "保存设备盘点信息，主子表同时新增")
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public ResultBean save(@RequestBody EquipCheckBean obj) {
		ResultBean resultBean = equipCheckService.save(obj);
		return resultBean;
	}

	@ApiOperation(value = "盘点修改，父表修改，子表新增")
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	public ResultBean update(@RequestBody EquipCheckBean obj) {
		return equipCheckService.update(obj);
	}

	@ApiOperation(value = "删除盘点单，以及盘点单详情")
	@RequestMapping(value = "/deleteBatchEquipCheck", method = RequestMethod.POST)
	public ResultBean deleteBatchEquipCheck(@RequestBody List<EquipCheck> list) {
		ResultBean resultBean = new ResultBean(true);
		try {
			resultBean = equipCheckService.deleteBatch(list);
		} catch (RuntimeException e) {
			resultBean.setSuccess(false);
			resultBean.setMessage(e.getMessage());
			return resultBean;
		}
		return resultBean;
	}

	@ApiOperation(value = "查询设备盘点单信息")
	@RequestMapping(value = "/selectByCondition", method = RequestMethod.POST)
	public ResultBean selectByCondition(@RequestBody EquipCheck obj) {

		return equipCheckService.selectByCondition(obj);
	}

	@ApiOperation(value = "盘点单确认")
	@RequestMapping("/checkConfirm")
	public ResultBean checkConfirm(@RequestBody List<Long> listId) {
		return equipCheckService.checkConfirm(listId);
	}

	@ApiOperation(value = "根据盘点单id获取盘点详情")
	@RequestMapping(value = "/selectEquipCheckDetailByCheckId", method = RequestMethod.POST)
	public ResultBean selectEquipCheckDetailByCheckId(@RequestBody EquipCheckDetailBean obj) {
		return equipCheckDetailService.selectEquipCheckDetailByCheckId(obj);
	}

	@ApiOperation(value = "批量删除设备盘点详情")
	@RequestMapping(value = "/deleteBatchEquipCheckDetail", method = RequestMethod.POST)
	public ResultBean deleteBatchCheckDetail(@RequestBody List<EquipCheckDetail> list) {
		return equipCheckDetailService.deleteBatch(list);
	}

	@ApiOperation(value = "批量盘点详情确认")
	@RequestMapping(value = "/equipCheckDetailChecked", method = RequestMethod.POST)
	public ResultBean equipCheckDetailChecked(@RequestBody List<EquipCheckDetail> list) {
		ResultBean resultBean = equipCheckDetailService.equipCheckDetailChecked(list);
		return resultBean;
	}
}
